<!DOCTYPE html>
<html>
<head>
    

    

    
<!-- Baidu Tongji -->
<script>var _hmt = _hmt || []</script>
<script async src="//hm.baidu.com/hm.js?a7c05ce530152d9866930ef4850ee566"></script>
<!-- End Baidu Tongji -->




    <meta charset="utf-8">
    
    
    
    <title>Redis数据类型和命令 | 神奇的鸭鸭の码农库 | 新知识要不断的总结记录成笔记，要多写，多画，能够清晰透彻的将知识讲给别人听，才是达到理解的层次。</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#765959">
    
    
    <meta name="keywords" content="缓存">
    <meta name="description" content="Redis数据类型redis基础入门中说过，目前为止Redis支持的键值数据类型如下：字符串类型，Hash散列类型，List列表类型，Set集合类型，SortedSet(Zset)有序集合类型，注意在redis中的命令语句中，命令是忽略大小写的，而key是不胡烈大小写的。 String类型基本命令：12345678910111213141516171819202122232425262728293">
<meta name="keywords" content="缓存">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis数据类型和命令">
<meta property="og:url" content="http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/index.html">
<meta property="og:site_name" content="神奇的鸭鸭の码农库">
<meta property="og:description" content="Redis数据类型redis基础入门中说过，目前为止Redis支持的键值数据类型如下：字符串类型，Hash散列类型，List列表类型，Set集合类型，SortedSet(Zset)有序集合类型，注意在redis中的命令语句中，命令是忽略大小写的，而key是不胡烈大小写的。 String类型基本命令：12345678910111213141516171819202122232425262728293">
<meta property="og:updated_time" content="2017-12-05T09:59:09.298Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Redis数据类型和命令">
<meta name="twitter:description" content="Redis数据类型redis基础入门中说过，目前为止Redis支持的键值数据类型如下：字符串类型，Hash散列类型，List列表类型，Set集合类型，SortedSet(Zset)有序集合类型，注意在redis中的命令语句中，命令是忽略大小写的，而key是不胡烈大小写的。 String类型基本命令：12345678910111213141516171819202122232425262728293">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.4.3">
    <script>window.lazyScripts=[]</script>
</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">神奇的鸭鸭</h5>
          <a href="mailto:702038338@qq.com" title="702038338@qq.com" class="mail">702038338@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://git.oschina.net/magic_duck" target="_blank" >
                <i class="icon icon-lg icon-gg-circle"></i>
                码云
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://www.zhihu.com/people/shen-qi-de-ya-ya" target="_blank" >
                <i class="icon icon-lg icon-twitter"></i>
                知乎
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/404.html"  >
                <i class="icon icon-lg icon-link"></i>
                404页面测试
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">Redis数据类型和命令</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">Redis数据类型和命令</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-09-05T18:00:00.000Z" itemprop="datePublished" class="page-time">
  2017-09-06
</time>


            
        </h5>
    </div>

    

</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Redis数据类型"><span class="post-toc-number">1.</span> <span class="post-toc-text">Redis数据类型</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#String类型"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">String类型</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Hash类型"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">Hash类型</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#List类型"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">List类型</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Set类型"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">Set类型</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#SortedSet类型zset"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">SortedSet类型zset</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Keys命令"><span class="post-toc-number">2.</span> <span class="post-toc-text">Keys命令</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#设置key的生存实践"><span class="post-toc-number">2.1.</span> <span class="post-toc-text">设置key的生存实践</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#其他命令"><span class="post-toc-number">2.2.</span> <span class="post-toc-text">其他命令</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-redis4.4.0_primary_02"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">Redis数据类型和命令</h1>
        <div class="post-meta">
            <time class="post-time" title="2017年09月06日 2:00" datetime="2017-09-05T18:00:00.000Z"  itemprop="datePublished">2017-09-06</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h2 id="Redis数据类型"><a href="#Redis数据类型" class="headerlink" title="Redis数据类型"></a>Redis数据类型</h2><p>redis基础入门中说过，目前为止Redis支持的键值数据类型如下：<strong>字符串类型，Hash散列类型，List列表类型，Set集合类型，SortedSet(Zset)有序集合类型</strong>，注意在redis中的命令语句中，命令是忽略大小写的，而key是不胡烈大小写的。</p>
<h3 id="String类型"><a href="#String类型" class="headerlink" title="String类型"></a>String类型</h3><p><strong>基本命令：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 赋值 SET key value</div><div class="line">127.0.0.1:6379&gt; set test 123</div><div class="line">OK</div><div class="line"></div><div class="line"><span class="meta">#</span> 取值 GET key</div><div class="line">127.0.0.1:6379&gt; get test</div><div class="line">"123"</div><div class="line"></div><div class="line"><span class="meta">#</span> 设置/获取多个键值 MSET key value [key value …]</div><div class="line">127.0.0.1:6379&gt; mset k1 v1 k2 v2 k3 v3</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; get k1</div><div class="line">"v1"</div><div class="line">127.0.0.1:6379&gt; mget k1 k3</div><div class="line">1) "v1"</div><div class="line">2) "v3"</div><div class="line"></div><div class="line"><span class="meta">#</span> 取值并赋值 GETSET key value</div><div class="line">127.0.0.1:6379&gt; getset s2 222</div><div class="line">"111"</div><div class="line">127.0.0.1:6379&gt; get s2</div><div class="line">"222"</div><div class="line"></div><div class="line"><span class="meta">#</span> 删除 DEL key</div><div class="line"></div><div class="line">127.0.0.1:6379&gt; del test</div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> 数值增减</div><div class="line"><span class="meta">#</span># 递增数值：当存储的字符串是整数时，Redis提供了一个实用的命令INCR，其作用是让当前键值递增，并返回递增后的值。</div><div class="line">127.0.0.1:6379&gt; incr num</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; incr num</div><div class="line">(integer) 2</div><div class="line">127.0.0.1:6379&gt; incr num</div><div class="line">(integer) 3</div><div class="line"><span class="meta">#</span># 增加指定的整数 INCRBY key increment</div><div class="line">127.0.0.1:6379&gt; incrby num 2</div><div class="line">(integer) 5</div><div class="line">127.0.0.1:6379&gt; incrby num 2</div><div class="line">(integer) 7</div><div class="line">127.0.0.1:6379&gt; incrby num 2</div><div class="line">(integer) 9</div><div class="line"><span class="meta">#</span># 递减数值 DECR key</div><div class="line">127.0.0.1:6379&gt; decr num</div><div class="line">(integer) 9</div><div class="line">127.0.0.1:6379&gt; decr num</div><div class="line">(integer) 8</div><div class="line"><span class="meta">#</span># 减少指定的整数 DECRBY key increment</div><div class="line">127.0.0.1:6379&gt; decr num</div><div class="line">(integer) 6</div><div class="line">127.0.0.1:6379&gt; decr num</div><div class="line">(integer) 5</div><div class="line">127.0.0.1:6379&gt; decrby num 3</div><div class="line">(integer) 2</div><div class="line">127.0.0.1:6379&gt; decrby num 3</div><div class="line">(integer) -1</div><div class="line"></div><div class="line"><span class="meta">#</span> 向尾部追加值：APPEND的作用是向键值的末尾追加value。如果键不存在则将该键的值设置为value，即相当于 SET key value。返回值是追加后字符串的总长度。 </div><div class="line">127.0.0.1:6379&gt; set str hello</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; append str " world!"</div><div class="line">(integer) 12</div><div class="line">127.0.0.1:6379&gt; get str </div><div class="line">"hello world!"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获取字符串长度：STRLEN命令返回键值的长度，如果键不存在则返回0。</div><div class="line">127.0.0.1:6379&gt; strlen str </div><div class="line">(integer) 0</div><div class="line">127.0.0.1:6379&gt; set str hello</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; strlen str </div><div class="line">(integer) 5</div></pre></td></tr></table></figure></p>
<p><strong>应用场景：自增主键：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 商品编号、订单号采用string的递增数字特性生成。定义商品编号key：items:id</div><div class="line">127.0.0.1:6379&gt; incr items:id</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; incr items:id</div><div class="line">(integer) 2</div></pre></td></tr></table></figure></p>
<h3 id="Hash类型"><a href="#Hash类型" class="headerlink" title="Hash类型"></a>Hash类型</h3><p>假设有User对象以JSON序列化的形式存储到Redis中，User对象有id，username、password、age、name等属性，存储的过程如下：<strong>User对象——json(string)——redis</strong>，如果在业务上只是更新age属性，其他的属性并不做更新我应该怎么做呢？ 如果仍然采用上边的方法在传输、处理时会造成资源浪费，下边的hash可以很好的解决这个问题。</p>
<p>hash叫散列类型，它提供了字段和字段值的映射。字段值只能是字符串类型，不支持散列类型、集合类型等其它类型。</p>
<p><strong>基本命令：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 赋值</div><div class="line"><span class="meta">#</span> HSET命令不区分插入和更新操作，当执行插入操作时HSET命令返回1，当执行更新操作时返回0</div><div class="line"><span class="meta">#</span> 一次只能设置一个字段值 HSET key field value</div><div class="line">127.0.0.1:6379&gt; hset user username zhangsan </div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> 一次可以设置多个字段值 HMSET key field value [field value]</div><div class="line">127.0.0.1:6379&gt; hmset user age 20 username lisi </div><div class="line">OK</div><div class="line"></div><div class="line"><span class="meta">#</span> 当字段不存在时赋值，类似HSET，区别在于如果字段存在，该命令不执行任何操作 HSETNX key field value</div><div class="line"><span class="meta">#</span> 如果user中没有age字段则设置age值为30，否则不做任何操作</div><div class="line">127.0.0.1:6379&gt; hsetnx user age 30</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 取值</div><div class="line"><span class="meta">#</span> 一次只能取一个字段 HGET key field</div><div class="line">127.0.0.1:6379&gt; hget user username</div><div class="line">"zhangsan"</div><div class="line"></div><div class="line"><span class="meta">#</span> 一次可以获取多个字段值 HMGET key field [field ...]</div><div class="line">127.0.0.1:6379&gt; hmget user age username</div><div class="line">1) "20"</div><div class="line">2) "lisi"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获取所有字段值 HGETALL key</div><div class="line">127.0.0.1:6379&gt; hgetall user</div><div class="line">1) "age"</div><div class="line">2) "20"</div><div class="line">3) "username"</div><div class="line">4) "lisi"</div><div class="line"></div><div class="line"><span class="meta">#</span> 删除</div><div class="line"><span class="meta">#</span> 可以删除一个或多个字段，返回值是被删除的字段个数 HDEL key field [field ...]</div><div class="line">127.0.0.1:6379&gt; hdel user age</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; hdel user age name</div><div class="line">(integer) 0</div><div class="line">127.0.0.1:6379&gt; hdel user age username</div><div class="line">(integer) 1 </div><div class="line"></div><div class="line"><span class="meta">#</span> 增加数字 HINCRBY key field increment</div><div class="line"><span class="meta">#</span> 将用户的年龄加2</div><div class="line">127.0.0.1:6379&gt; hincrby user age 2	</div><div class="line">(integer) 22</div><div class="line"><span class="meta">#</span> 获取用户的年龄</div><div class="line">127.0.0.1:6379&gt; hget user age		</div><div class="line">"22"</div><div class="line"></div><div class="line"><span class="meta">#</span> hex判断字段是否存在 HEXISTS key field</div><div class="line"><span class="meta">#</span> 查看user中是否有age字段</div><div class="line">127.0.0.1:6379&gt; hexists user age		</div><div class="line">(integer) 1</div><div class="line"><span class="meta">#</span> 查看user中是否有name字段</div><div class="line">127.0.0.1:6379&gt; hexists user name	</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 只获取字段名或字段值 HKEYS key HVALS key</div><div class="line">127.0.0.1:6379&gt; hmset user age 20 name lisi</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; hkeys user</div><div class="line">1) "age"</div><div class="line">2) "name"</div><div class="line">3) "username"</div><div class="line">127.0.0.1:6379&gt; hvals user</div><div class="line">1) "20"</div><div class="line">2) "lisi"</div><div class="line">3) "like"</div><div class="line">127.0.0.1:6379&gt; </div><div class="line"></div><div class="line"><span class="meta">#</span> 获取字段数量 HLEN key</div><div class="line">127.0.0.1:6379&gt; hlen user</div><div class="line">(integer) 3</div></pre></td></tr></table></figure></p>
<p><strong>应用场景：存储商品信息：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 存储商品信息：字段[商品id、商品名称、商品描述、商品库存、商品好评]</div><div class="line"><span class="meta">#</span> 商品1001的信息在 Redis中的key为：[items:1001] 存储商品</div><div class="line">192.168.101.3:7003&gt; HMSET items:1001 id 3 name apple price 999.9</div><div class="line">OK</div><div class="line"><span class="meta">#</span> 获取商品信息</div><div class="line">192.168.101.3:7003&gt; HGET items:1001 id</div><div class="line">"3"</div><div class="line">192.168.101.3:7003&gt; HGETALL items:1001</div><div class="line">1) "id"</div><div class="line">2) "3"</div><div class="line">3) "name"</div><div class="line">4) "apple"</div><div class="line">5) "price"</div><div class="line">6) "999.9"</div></pre></td></tr></table></figure></p>
<h3 id="List类型"><a href="#List类型" class="headerlink" title="List类型"></a>List类型</h3><p>列表类型（list）可以存储一个有序的字符串列表，常用的操作是向列表两端添加元素，或者获得列表的某一个片段。列表类型内部是使用<strong>双向链表（double linked list）</strong>实现的，所以向列表两端添加元素的时间复杂度为0(1)，获取越接近两端的元素速度就越快。这意味着即使是一个有几千万个元素的列表，获取头部或尾部的10条记录也是极快的。</p>
<p><strong>基本命令：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 向列表左边增加元素 LPUSH key value[value ...]</div><div class="line">127.0.0.1:6379&gt; lpush list:1 1 2 3</div><div class="line">(integer) 3</div><div class="line"></div><div class="line"><span class="meta">#</span> 向列表右边增加元素 RPUSH key value[value ...]</div><div class="line">127.0.0.1:6379&gt; rpush list:1 4 5 6</div><div class="line">(integer) 3</div><div class="line"></div><div class="line"><span class="meta">#</span> 获取列表中的某一片段，将返回start、stop之间的所有元素（包含两端的元素），索引从0开始。索引可以是负数，如：“-1”代表最后边的一个元素。</div><div class="line"><span class="meta">#</span> 查看列表 LRANGE key start stop</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 2</div><div class="line">1) "2"</div><div class="line">2) "1"</div><div class="line">3) "4"</div><div class="line"></div><div class="line"><span class="meta">#</span> 从列表两端弹出元素 LPOP key / RPOP key 会分两步完成：</div><div class="line"><span class="meta">#</span> 第一步是将列表左边/右边的元素从列表中移除</div><div class="line"><span class="meta">#</span> 第二步是返回被移除的元素值。</div><div class="line">127.0.0.1:6379&gt; lpop list:1</div><div class="line">"3"</div><div class="line">127.0.0.1:6379&gt; rpop list:1</div><div class="line">"6"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获取列表中元素的个数 LLEN key</div><div class="line">127.0.0.1:6379&gt; llen list:1</div><div class="line">(integer) 2</div><div class="line"></div><div class="line"><span class="meta">#</span> 删除列表中指定的值 LREM key count value</div><div class="line"><span class="meta">#</span> LREM命令会删除列表中前count个值为value的元素，返回实际删除的元素个数。</div><div class="line"><span class="meta">#</span> 当count&gt;0时， LREM会从列表左边开始删除。 </div><div class="line"><span class="meta">#</span> 当count&lt;0时， LREM会从列表后边开始删除。 </div><div class="line"><span class="meta">#</span> 当count=0时， LREM删除所有值为value的元素。 </div><div class="line">127.0.0.1:6379&gt; lrem  list:1 2 10</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得/设置指定索引的元素值 LINDEX key index</div><div class="line">127.0.0.1:6379&gt; lindex list:1 2</div><div class="line">"1"</div><div class="line"></div><div class="line"><span class="meta">#</span> 设置指定索引的元素值 LSET key index value</div><div class="line">127.0.0.1:6379&gt; lset list:1 2 2</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "6"</div><div class="line">2) "5"</div><div class="line">3) "2"</div><div class="line">4) "2"</div><div class="line"></div><div class="line"><span class="meta">#</span> 只保留列表指定片段 指定范围和LRANGE一致 LTRIM key start stop</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "6"</div><div class="line">2) "5"</div><div class="line">3) "0"</div><div class="line">4) "2"</div><div class="line">127.0.0.1:6379&gt; ltrim list:1 0 2</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "6"</div><div class="line">2) "5"</div><div class="line">3) "0"</div><div class="line"></div><div class="line"><span class="meta">#</span> 向列表中插入元素 LINSERT key BEFORE|AFTER pivot value</div><div class="line"><span class="meta">#</span> 该命令首先会在列表中从左到右查找值为pivot的元素，然后根据第二个参数是BEFORE还是AFTER来决定将value插入到该元素的前面还是后面。 </div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "3"</div><div class="line">2) "2"</div><div class="line">3) "1"</div><div class="line">127.0.0.1:6379&gt; linsert list:1 after 3 4</div><div class="line">(integer) 4</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "3"</div><div class="line">2) "4"</div><div class="line">3) "2"</div><div class="line">4) "1"</div><div class="line"></div><div class="line"><span class="meta">#</span> 将元素从一个列表转移到另一个列表中 RPOPLPUSH source destination</div><div class="line">127.0.0.1:6379&gt; rpoplpush list:1 list:2</div><div class="line">"1"</div><div class="line">127.0.0.1:6379&gt; lrange list:2 0 -1</div><div class="line">1) "1"</div><div class="line">127.0.0.1:6379&gt; lrange list:1 0 -1</div><div class="line">1) "3"</div><div class="line">2) "4"</div><div class="line">3) "2"</div></pre></td></tr></table></figure></p>
<p><strong>应用场景：商品评论列表：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 在Redis中创建商品评论列表，用户发布商品评论，将评论信息转成json存储到list中。用户在页面查询评论列表，从redis中取出json数据展示到页面</div><div class="line">127.0.0.1:6379&gt; LPUSH items:comment:1001 '&#123;"id":1,"name":"商品不错，很好！！","date":1430295077289&#125;'</div></pre></td></tr></table></figure></p>
<h3 id="Set类型"><a href="#Set类型" class="headerlink" title="Set类型"></a>Set类型</h3><p>和list相反：无序、不可重复</p>
<p><strong>基本命令：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 增加/删除元素 SADD key member [member ...] / SREM key member [member ...]</div><div class="line">127.0.0.1:6379&gt; sadd set a b c</div><div class="line">(integer) 3</div><div class="line">127.0.0.1:6379&gt; sadd set a</div><div class="line">(integer) 0</div><div class="line">127.0.0.1:6379&gt; srem set c d</div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得集合中的所有元素 SMEMBERS key</div><div class="line">127.0.0.1:6379&gt; smembers set</div><div class="line">1) "a"</div><div class="line">2) "b"</div><div class="line"></div><div class="line"><span class="meta">#</span> 判断元素是否在集合中 SISMEMBER key member</div><div class="line">127.0.0.1:6379&gt; sismember set a</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; sismember set h</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 运算命令</div><div class="line"><span class="meta">#</span># 集合的差集运算 A-B 属于A并且不属于B的元素构成的集合 SDIFF key [key ...]</div><div class="line">127.0.0.1:6379&gt; sismember set a</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; sismember set h</div><div class="line">(integer) 0</div><div class="line">127.0.0.1:6379&gt; sadd setA 1 2 3 </div><div class="line">(integer) 3</div><div class="line">127.0.0.1:6379&gt; sadd setB 2 3 4 </div><div class="line">(integer) 3</div><div class="line">127.0.0.1:6379&gt; sdiff setA setB</div><div class="line">1) "1"</div><div class="line">127.0.0.1:6379&gt; sdiff setB setA</div><div class="line">1) "4"</div><div class="line"></div><div class="line"><span class="meta">#</span># 集合的交集运算 A ∩ B 属于A且属于B的元素构成的集合 SINTER key [key ...] </div><div class="line">127.0.0.1:6379&gt; sinter setA setB</div><div class="line">1) "2"</div><div class="line">2) "3"</div><div class="line"></div><div class="line"><span class="meta">#</span># 集合的并集运算 A ∪ B 属于A或者属于B的元素构成的集合 SUNION key [key ...]</div><div class="line">127.0.0.1:6379&gt; sunion setA setB</div><div class="line">1) "1"</div><div class="line">2) "2"</div><div class="line">3) "3"</div><div class="line">4) "4"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得集合中元素的个数 SCARD key</div><div class="line">127.0.0.1:6379&gt; scard setA</div><div class="line">(integer) 3</div><div class="line"></div><div class="line"><span class="meta">#</span> 从集合中弹出一个元素 SPOP key</div><div class="line">127.0.0.1:6379&gt; spop setA</div><div class="line">"3"</div></pre></td></tr></table></figure></p>
<h3 id="SortedSet类型zset"><a href="#SortedSet类型zset" class="headerlink" title="SortedSet类型zset"></a>SortedSet类型zset</h3><p>SortedSet又叫zset，SortedSet是有序集合，可排序，但是唯一。它与set的区别在于，它会给set中的元素添加一个分数，然后通过这个分数进行排序。</p>
<p><strong>基本命令：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 增加元素 ZADD key member [score member ...]</div><div class="line"><span class="meta">#</span> 向有序集合中加入一个元素和该元素的分数，如果该元素已经存在则会用新的分数替换原有的分数。返回值是新加入到集合中的元素个数，不包含之前已经存在的元素。 </div><div class="line">127.0.0.1:6379&gt; zadd scoreboard 80 zhangsan 89 lisi 94 wangwu</div><div class="line">(integer) 3</div><div class="line">127.0.0.1:6379&gt; zadd scoreboard 97 lisi</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 获取元素的分数 ZSCORE key member</div><div class="line">127.0.0.1:6379&gt; zscore scoreboard lisi</div><div class="line">"97"</div><div class="line"></div><div class="line"><span class="meta">#</span> 删除元素 ZREM key member [member ...]</div><div class="line"><span class="meta">#</span> 移除有序集key中的一个或多个成员，不存在的成员将被忽略。当key存在但不是有序集类型时，返回一个错误。</div><div class="line">127.0.0.1:6379&gt; zrem scoreboard lisi</div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得排名在某个范围的元素列表</div><div class="line"><span class="meta">#</span># 按照元素分数从小到大的顺序返回索引从start到stop之间的所有元素（包含两端的元素）</div><div class="line">127.0.0.1:6379&gt; zrange scoreboard 0 2</div><div class="line">1) "zhangsan"</div><div class="line">2) "wangwu"</div><div class="line">3) "lisi"</div><div class="line"></div><div class="line"><span class="meta">#</span># 按照元素分数从大到小的顺序返回索引从start到stop之间的所有元素（包含两端的元素）</div><div class="line">127.0.0.1:6379&gt; zrevrange scoreboard 0 2</div><div class="line">1) "lisi"</div><div class="line">2) "wangwu"</div><div class="line">3) "zhangsan"</div><div class="line"></div><div class="line"><span class="meta">#</span># 如果需要获得元素的分数的可以在命令尾部加上WITHSCORES参数</div><div class="line">127.0.0.1:6379&gt; zrevrange scoreboard 0 2 withscores</div><div class="line">1) "lisi"</div><div class="line">2) "97"</div><div class="line">3) "wangwu"</div><div class="line">4) "94"</div><div class="line">5) "zhangsan"</div><div class="line">6) "80"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得指定分数范围的元素 ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]</div><div class="line">127.0.0.1:6379&gt; zrangebyscore scoreboard 90 97 withscores</div><div class="line">1) "wangwu"</div><div class="line">2) "94"</div><div class="line">3) "lisi"</div><div class="line">4) "97"</div><div class="line">127.0.0.1:6379&gt; zrangebyscore scoreboard 70 100 limit 1 2</div><div class="line">1) "wangwu"</div><div class="line">2) "lisi"</div><div class="line"></div><div class="line"><span class="meta">#</span> 增加某个元素的分数 返回值是更改后的分数 ZINCRBY key increment member</div><div class="line">127.0.0.1:6379&gt; zincrby scoreboard 4 lisi</div><div class="line">"101"</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得集合中元素的数量 ZCARD key</div><div class="line">127.0.0.1:6379&gt; zcard scoreboard</div><div class="line">(integer) 3</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得指定分数范围内的元素个数 ZCOUNT key min max</div><div class="line">127.0.0.1:6379&gt; zcount scoreboard 80 90</div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> 按照排名范围删除元素 ZREMRANGEBYRANK key start stop</div><div class="line">127.0.0.1:6379&gt; zremrangebyrank scoreboard 0 1</div><div class="line">(integer) 2</div><div class="line">127.0.0.1:6379&gt; zrange scoreboard 0 -1</div><div class="line">1) "lisi"</div><div class="line"></div><div class="line"><span class="meta">#</span> 按照分数范围删除元素 ZREMRANGEBYSCORE key min max</div><div class="line">127.0.0.1:6379&gt; zremrangebyscore scoreboard 80 100</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> 获得元素排名</div><div class="line"><span class="meta">#</span># 从小到大 ZRANK key member    </div><div class="line">127.0.0.1:6379&gt; zrank scoreboard lisi</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span># 从大到小 ZREVRANK key member</div><div class="line">127.0.0.1:6379&gt; zrevrank scoreboard zhangsan</div><div class="line">(nil)</div></pre></td></tr></table></figure></p>
<p><strong>应用场景：商品销售排行榜：</strong><br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> 根据商品销售量对商品进行排行显示。定义商品销售排行榜（sorted set集合），Key为items:sellsort，分数为商品销售量。</div><div class="line"><span class="meta">#</span> 写入商品销售量 商品编号1001的销量是9，商品编号1002的销量是10</div><div class="line">127.0.0.1:6379&gt; zadd items:sellsort 9 1001 10 1002</div><div class="line">(integer) 2</div><div class="line"></div><div class="line"><span class="meta">#</span> 商品编号1001的销量加1</div><div class="line">127.0.0.1:6379&gt; zincrby items:sellsort 1 1001</div><div class="line">"10"</div><div class="line"></div><div class="line"><span class="meta">#</span> 商品销量前10：</div><div class="line">127.0.0.1:6379&gt; zrange items:sellsort 0 9 withscores</div><div class="line">1) "1001"</div><div class="line">2) "10"</div><div class="line">3) "1002"</div><div class="line">4) "10"</div></pre></td></tr></table></figure></p>
<hr>
<h2 id="Keys命令"><a href="#Keys命令" class="headerlink" title="Keys命令"></a>Keys命令</h2><h3 id="设置key的生存实践"><a href="#设置key的生存实践" class="headerlink" title="设置key的生存实践"></a>设置key的生存实践</h3><p>Redis在实际使用过程中更多的用作缓存，然而缓存的数据一般都是需要设置生存时间的，即：到期后数据销毁。<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> EXPIRE key seconds 设置key的生存时间（单位：秒）key在多少秒后会自动删除</div><div class="line"><span class="meta">#</span> TTL key 查看key剩余的生存时间</div><div class="line"><span class="meta">#</span> PERSIST key 清除生存时间 </div><div class="line"><span class="meta">#</span> PEXPIRE key milliseconds 生存时间设置单位为：毫秒</div><div class="line">192.168.101.3:7002&gt; set test 1		设置test的值为1</div><div class="line">OK</div><div class="line">192.168.101.3:7002&gt; get test			获取test的值</div><div class="line">"1"</div><div class="line">192.168.101.3:7002&gt; EXPIRE test 5	设置test的生存时间为5秒</div><div class="line">(integer) 1</div><div class="line">192.168.101.3:7002&gt; TTL test			查看test的生于生成时间还有1秒删除</div><div class="line">(integer) 1</div><div class="line">192.168.101.3:7002&gt; TTL test</div><div class="line">(integer) -2</div><div class="line">192.168.101.3:7002&gt; get test			获取test的值，已经删除</div><div class="line">(nil)</div></pre></td></tr></table></figure></p>
<h3 id="其他命令"><a href="#其他命令" class="headerlink" title="其他命令"></a>其他命令</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#</span> keys 返回满足给定pattern 的所有key</div><div class="line">127.0.0.1:6379&gt; keys k*</div><div class="line">1) "k3"</div><div class="line">2) "k2"</div><div class="line">3) "k1"</div><div class="line"></div><div class="line"><span class="meta">#</span> exists 确认一个key 是否存在</div><div class="line">127.0.0.1:6379&gt; exists k3</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; exists k4</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> del 删除一个key</div><div class="line">127.0.0.1:6379&gt; del k3</div><div class="line">(integer) 1</div><div class="line">127.0.0.1:6379&gt; exists k3</div><div class="line">(integer) 0</div><div class="line"></div><div class="line"><span class="meta">#</span> rename 重命名key</div><div class="line">127.0.0.1:6379&gt; rename k2 k3</div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; exists k3</div><div class="line">(integer) 1</div><div class="line"></div><div class="line"><span class="meta">#</span> type 返回值的类型</div><div class="line">127.0.0.1:6379&gt; type mytest</div><div class="line">string</div><div class="line">127.0.0.1:6379&gt; type setA</div><div class="line">set</div><div class="line">127.0.0.1:6379&gt; type list:1</div><div class="line">list</div><div class="line">127.0.0.1:6379&gt; type scoreboard</div><div class="line">zset</div></pre></td></tr></table></figure>
        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-12-05T09:59:09.298Z" itemprop="dateUpdated">2017年12月5日 17:59</time>
</span><br>


        如要转载请注明出处：<a href="/2017/09/06/redis4.4.0_primary_02/" target="_blank" rel="external">http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/</a>
    </div>
    <footer>
        <a href="http://magic_duck.oschina.io">
            <img src="/img/avatar.jpg" alt="神奇的鸭鸭">
            神奇的鸭鸭
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/缓存/">缓存</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&title=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&pic=http://magic_duck.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&title=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&via=http://magic_duck.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/09/06/redis4.4.0_primary_03/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">Redis持久化方案</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/09/06/redis4.4.0_primary_01/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">Redis基础入门</h4>
      </a>
    </div>
  
</nav>



    







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        我只要一角钱~ ~
        <i class="icon icon-quote-right"></i>
    </h3>
    <ul class="reward-items">
        
        <li>
            <img src="/img/wechat.png" title="微信打赏二维码" alt="微信打赏二维码">
            <p>微信</p>
        </li>
        

        
        <li>
            <img src="/img/alipay.jpg" title="支付宝打赏二维码" alt="支付宝打赏二维码">
            <p>支付宝</p>
        </li>
        
    </ul>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            <span><a href="" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            <span>博客内容遵循 <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p>
            <span>Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://git.oschina.net/z77z" target="_blank">邹海清</a></span>
            <span>神奇的鸭鸭の码农库 &copy; 2017</span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&title=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&pic=http://magic_duck.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&title=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《Redis数据类型和命令》 — 神奇的鸭鸭の码农库&url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/&via=http://magic_duck.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://magic_duck.oschina.io/2017/09/06/redis4.4.0_primary_02/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };



lazyScripts.push('//s95.cnzz.com/z_stat.php?id=1261081671&web_id=1261081671')

</script>

<script src="/js/main.min.js?v=1.4.3"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.4.3" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>


</body>
</html>
